﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;

namespace IHISCETeim.DAL
{
    class TestDAL
    {
        /// <summary>
        /// 事务
        /// </summary>
        /// <param name="transactionAmount"></param>
        /// <param name="sourceAccount"></param>
        /// <param name="destinationAccount"></param>
        public void Transfer()
        {
            Database db = DatabaseFactory.CreateDatabase();

            //db.LoadDataSet(
            using (DbConnection conn = db.CreateConnection())
            {
            //打开连接
                            conn.Open();
            //创建事务
                            DbTransaction trans = conn.BeginTransaction();
            try
            {
            //执行语句1；
                //db.ExecuteNonQuery(creditCommandWrapper, trans);
                //// Debit the second account
                //db.ExecuteNonQuery(debitCommandWrapper, trans);

            //执行语句2；
            //都执行成功则提交事务
                                trans.Commit();
            }
            catch(Exception)
            {
            //发生异常，事务回滚
                                trans.Rollback();
            }
            //关闭连接
                            conn.Close();
            }
        }

    }
}
